package com.yang.controller;

import com.yang.service.DataStatisticsService;
import com.yang.util.PublicUtil;
import org.jboss.logging.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.SimpleFormatter;

@Controller
public class DataStatisticsController {
    private static Logger logger = Logger.getLogger(DataStatisticsController.class);

    @Resource
    DataStatisticsService dataStatisticsService;

    /**
     * 顾客订单查找
     * @param orderBeginTime
     * @param orderOverTime
     * @return
     */
    @RequestMapping(produces = "application/json;charset=UTF-8",value = "admin/orderSelect",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> orderSelect(String orderBeginTime,String orderOverTime){
        Map<String,Object> map = new HashMap<String, Object>();

        if(orderBeginTime==null ||orderOverTime==null||orderOverTime.equals("")||orderBeginTime.equals("")){
            map.put("status","error");
            map.put("info","日期输入为空");
            logger.error("日期输入为空！");
            return map;
        }
        orderBeginTime = orderBeginTime.replaceAll("-","");
        orderOverTime = orderOverTime.replaceAll("-","");
        logger.info("orderBeginTime = "+orderBeginTime +"orderOverTime = "+orderOverTime);
        //把时间转成毫秒级
        long beginTime = PublicUtil.chargeDatToMillis(orderBeginTime);
        long overTime = PublicUtil.chargeDatToMillis(orderOverTime);
        logger.info("beginTime = "+beginTime +"overTime = "+overTime);


        map = dataStatisticsService.orderSelect(beginTime,overTime);

        return map;
    }

    /**
     * 顾客信息查找
     * @param guestBeginTime
     * @param guestOverTime
     * @return
     */
    @RequestMapping(produces = "application/json;charset=UTF-8",value = "admin/guestSelect",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> guestSelect(String guestBeginTime,String guestOverTime){
        Map<String,Object> map = new HashMap<String, Object>();

        if(guestBeginTime==null ||guestOverTime==null||guestBeginTime.equals("")||guestOverTime.equals("")){
            map.put("status","error");
            map.put("info","日期输入为空");
            logger.error("日期输入为空！");
            return map;
        }
        guestBeginTime = guestBeginTime.replaceAll("-","");
        guestOverTime = guestOverTime.replaceAll("-","");

        //把时间转成毫秒级
        long beginTime = PublicUtil.chargeDatToMillis(guestBeginTime);
        long overTime = PublicUtil.chargeDatToMillis(guestOverTime);

        map = dataStatisticsService.guestSelect(beginTime,overTime);
        return map;
    }

}
